﻿Imports iMESMainMenu
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinToolbars
Public Class MDI_Panel

    Inherits System.Windows.Forms.Form

    '//Data
    Dim dsData As New DataSet
    Dim ModuleNo As String
    Dim strUserPriv As String

    '//其他共用變數
    Dim i As Integer
    Dim blnShow As Boolean
    Dim imlMDI As New ImageList

    '// MainMenu & ToolBar變數
    Dim utbMDI As Infragistics.Win.UltraWinToolbars.UltraToolbar = New UltraToolbar("ToolBar")
    Dim utbMDIMenu As Infragistics.Win.UltraWinToolbars.UltraToolbar = New UltraToolbar("MainMenu")
    Dim OptionSet1 As Infragistics.Win.UltraWinToolbars.OptionSet = New Infragistics.Win.UltraWinToolbars.OptionSet("LanguageMode")
    Dim btlMDI As ButtonTool
    Dim popMDI As PopupMenuTool
    Dim sbtMDI As StateButtonTool


#Region " Windows Form 設計工具產生的程式碼 "

    Public Sub New()
        MyBase.New()

        '此呼叫為 Windows Form 設計工具的必要項。
        InitializeComponent()

        '在 InitializeComponent() 呼叫之後加入所有的初始設定

    End Sub

    'Form 覆寫 Dispose 以清除元件清單。
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    '為 Windows Form 設計工具的必要項
    Private components As System.ComponentModel.IContainer

    '注意: 以下為 Windows Form 設計工具所需的程序
    '您可以使用 Windows Form 設計工具進行修改。
    '請勿使用程式碼編輯器來修改這些程序。
    Friend WithEvents UltraToolbarsManager1 As Infragistics.Win.UltraWinToolbars.UltraToolbarsManager
    Friend WithEvents _MDIENT_Panel_Toolbars_Dock_Area_Left As Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea
    Friend WithEvents _MDIENT_Panel_Toolbars_Dock_Area_Right As Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea
    Friend WithEvents _MDIENT_Panel_Toolbars_Dock_Area_Top As Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea
    Friend WithEvents _MDIENT_Panel_Toolbars_Dock_Area_Bottom As Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea
    Friend WithEvents UltraDockManager1 As Infragistics.Win.UltraWinDock.UltraDockManager
    Friend WithEvents _MDIENT_PanelUnpinnedTabAreaLeft As Infragistics.Win.UltraWinDock.UnpinnedTabArea
    Friend WithEvents _MDIENT_PanelUnpinnedTabAreaRight As Infragistics.Win.UltraWinDock.UnpinnedTabArea
    Friend WithEvents _MDIENT_PanelUnpinnedTabAreaTop As Infragistics.Win.UltraWinDock.UnpinnedTabArea
    Friend WithEvents _MDIENT_PanelUnpinnedTabAreaBottom As Infragistics.Win.UltraWinDock.UnpinnedTabArea
    Friend WithEvents _MDIENT_PanelAutoHideControl As Infragistics.Win.UltraWinDock.AutoHideControl
    Friend WithEvents uebMenu As Infragistics.Win.UltraWinExplorerBar.UltraExplorerBar
    Friend WithEvents WindowDockingArea1 As Infragistics.Win.UltraWinDock.WindowDockingArea
    Friend WithEvents DockableWindow1 As Infragistics.Win.UltraWinDock.DockableWindow
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Dim DockAreaPane1 As Infragistics.Win.UltraWinDock.DockAreaPane = New Infragistics.Win.UltraWinDock.DockAreaPane(Infragistics.Win.UltraWinDock.DockedLocation.DockedLeft, New System.Guid("8666bbed-9885-4c68-819e-c049f9eac535"))
        Dim DockableControlPane1 As Infragistics.Win.UltraWinDock.DockableControlPane = New Infragistics.Win.UltraWinDock.DockableControlPane(New System.Guid("5a475b0e-96d9-4cd0-973b-da8cba709615"), New System.Guid("00000000-0000-0000-0000-000000000000"), -1, New System.Guid("8666bbed-9885-4c68-819e-c049f9eac535"), -1)
        Me.uebMenu = New Infragistics.Win.UltraWinExplorerBar.UltraExplorerBar()
        Me.UltraToolbarsManager1 = New Infragistics.Win.UltraWinToolbars.UltraToolbarsManager(Me.components)
        Me._MDIENT_Panel_Toolbars_Dock_Area_Left = New Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea()
        Me._MDIENT_Panel_Toolbars_Dock_Area_Right = New Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea()
        Me._MDIENT_Panel_Toolbars_Dock_Area_Top = New Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea()
        Me._MDIENT_Panel_Toolbars_Dock_Area_Bottom = New Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea()
        Me.UltraDockManager1 = New Infragistics.Win.UltraWinDock.UltraDockManager(Me.components)
        Me._MDIENT_PanelUnpinnedTabAreaLeft = New Infragistics.Win.UltraWinDock.UnpinnedTabArea()
        Me._MDIENT_PanelUnpinnedTabAreaRight = New Infragistics.Win.UltraWinDock.UnpinnedTabArea()
        Me._MDIENT_PanelUnpinnedTabAreaTop = New Infragistics.Win.UltraWinDock.UnpinnedTabArea()
        Me._MDIENT_PanelUnpinnedTabAreaBottom = New Infragistics.Win.UltraWinDock.UnpinnedTabArea()
        Me._MDIENT_PanelAutoHideControl = New Infragistics.Win.UltraWinDock.AutoHideControl()
        Me.DockableWindow1 = New Infragistics.Win.UltraWinDock.DockableWindow()
        Me.WindowDockingArea1 = New Infragistics.Win.UltraWinDock.WindowDockingArea()
        CType(Me.uebMenu, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.UltraToolbarsManager1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.UltraDockManager1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me._MDIENT_PanelAutoHideControl.SuspendLayout()
        Me.DockableWindow1.SuspendLayout()
        Me.SuspendLayout()
        '
        'uebMenu
        '
        Me.uebMenu.Location = New System.Drawing.Point(0, 23)
        Me.uebMenu.Name = "uebMenu"
        Me.uebMenu.SettingsKey = ""
        Me.uebMenu.Size = New System.Drawing.Size(420, 545)
        Me.uebMenu.TabIndex = 10
        '
        'UltraToolbarsManager1
        '
        Me.UltraToolbarsManager1.DesignerFlags = 1
        Me.UltraToolbarsManager1.DockWithinContainer = Me
        Me.UltraToolbarsManager1.DockWithinContainerBaseType = GetType(System.Windows.Forms.Form)
        Me.UltraToolbarsManager1.SettingsKey = ""
        '
        '_MDIENT_Panel_Toolbars_Dock_Area_Left
        '
        Me._MDIENT_Panel_Toolbars_Dock_Area_Left.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping
        Me._MDIENT_Panel_Toolbars_Dock_Area_Left.BackColor = System.Drawing.SystemColors.Control
        Me._MDIENT_Panel_Toolbars_Dock_Area_Left.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Left
        Me._MDIENT_Panel_Toolbars_Dock_Area_Left.ForeColor = System.Drawing.SystemColors.ControlText
        Me._MDIENT_Panel_Toolbars_Dock_Area_Left.Location = New System.Drawing.Point(0, 0)
        Me._MDIENT_Panel_Toolbars_Dock_Area_Left.Name = "_MDIENT_Panel_Toolbars_Dock_Area_Left"
        Me._MDIENT_Panel_Toolbars_Dock_Area_Left.Size = New System.Drawing.Size(0, 442)
        Me._MDIENT_Panel_Toolbars_Dock_Area_Left.ToolbarsManager = Me.UltraToolbarsManager1
        '
        '_MDIENT_Panel_Toolbars_Dock_Area_Right
        '
        Me._MDIENT_Panel_Toolbars_Dock_Area_Right.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping
        Me._MDIENT_Panel_Toolbars_Dock_Area_Right.BackColor = System.Drawing.SystemColors.Control
        Me._MDIENT_Panel_Toolbars_Dock_Area_Right.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Right
        Me._MDIENT_Panel_Toolbars_Dock_Area_Right.ForeColor = System.Drawing.SystemColors.ControlText
        Me._MDIENT_Panel_Toolbars_Dock_Area_Right.Location = New System.Drawing.Point(624, 0)
        Me._MDIENT_Panel_Toolbars_Dock_Area_Right.Name = "_MDIENT_Panel_Toolbars_Dock_Area_Right"
        Me._MDIENT_Panel_Toolbars_Dock_Area_Right.Size = New System.Drawing.Size(0, 442)
        Me._MDIENT_Panel_Toolbars_Dock_Area_Right.ToolbarsManager = Me.UltraToolbarsManager1
        '
        '_MDIENT_Panel_Toolbars_Dock_Area_Top
        '
        Me._MDIENT_Panel_Toolbars_Dock_Area_Top.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping
        Me._MDIENT_Panel_Toolbars_Dock_Area_Top.BackColor = System.Drawing.SystemColors.Control
        Me._MDIENT_Panel_Toolbars_Dock_Area_Top.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Top
        Me._MDIENT_Panel_Toolbars_Dock_Area_Top.ForeColor = System.Drawing.SystemColors.ControlText
        Me._MDIENT_Panel_Toolbars_Dock_Area_Top.Location = New System.Drawing.Point(0, 0)
        Me._MDIENT_Panel_Toolbars_Dock_Area_Top.Name = "_MDIENT_Panel_Toolbars_Dock_Area_Top"
        Me._MDIENT_Panel_Toolbars_Dock_Area_Top.Size = New System.Drawing.Size(624, 0)
        Me._MDIENT_Panel_Toolbars_Dock_Area_Top.ToolbarsManager = Me.UltraToolbarsManager1
        '
        '_MDIENT_Panel_Toolbars_Dock_Area_Bottom
        '
        Me._MDIENT_Panel_Toolbars_Dock_Area_Bottom.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping
        Me._MDIENT_Panel_Toolbars_Dock_Area_Bottom.BackColor = System.Drawing.SystemColors.Control
        Me._MDIENT_Panel_Toolbars_Dock_Area_Bottom.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Bottom
        Me._MDIENT_Panel_Toolbars_Dock_Area_Bottom.ForeColor = System.Drawing.SystemColors.ControlText
        Me._MDIENT_Panel_Toolbars_Dock_Area_Bottom.Location = New System.Drawing.Point(0, 442)
        Me._MDIENT_Panel_Toolbars_Dock_Area_Bottom.Name = "_MDIENT_Panel_Toolbars_Dock_Area_Bottom"
        Me._MDIENT_Panel_Toolbars_Dock_Area_Bottom.Size = New System.Drawing.Size(624, 0)
        Me._MDIENT_Panel_Toolbars_Dock_Area_Bottom.ToolbarsManager = Me.UltraToolbarsManager1
        '
        'UltraDockManager1
        '
        DockableControlPane1.Control = Me.uebMenu
        DockableControlPane1.FlyoutSize = New System.Drawing.Size(239, -1)
        DockableControlPane1.Key = "WIPModule"
        DockableControlPane1.OriginalControlBounds = New System.Drawing.Rectangle(208, 112, 175, 230)
        DockableControlPane1.Pinned = False
        DockableControlPane1.Size = New System.Drawing.Size(100, 100)
        DockableControlPane1.Text = "WIP"
        DockAreaPane1.Panes.AddRange(New Infragistics.Win.UltraWinDock.DockablePaneBase() {DockableControlPane1})
        DockAreaPane1.Size = New System.Drawing.Size(239, 294)
        Me.UltraDockManager1.DockAreas.AddRange(New Infragistics.Win.UltraWinDock.DockAreaPane() {DockAreaPane1})
        Me.UltraDockManager1.HostControl = Me
        Me.UltraDockManager1.SettingsKey = ""
        Me.UltraDockManager1.ShowCloseButton = False
        '
        '_MDIENT_PanelUnpinnedTabAreaLeft
        '
        Me._MDIENT_PanelUnpinnedTabAreaLeft.Dock = System.Windows.Forms.DockStyle.Left
        Me._MDIENT_PanelUnpinnedTabAreaLeft.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))
        Me._MDIENT_PanelUnpinnedTabAreaLeft.Location = New System.Drawing.Point(0, 0)
        Me._MDIENT_PanelUnpinnedTabAreaLeft.Name = "_MDIENT_PanelUnpinnedTabAreaLeft"
        Me._MDIENT_PanelUnpinnedTabAreaLeft.Owner = Me.UltraDockManager1
        Me._MDIENT_PanelUnpinnedTabAreaLeft.Size = New System.Drawing.Size(21, 442)
        Me._MDIENT_PanelUnpinnedTabAreaLeft.TabIndex = 5
        '
        '_MDIENT_PanelUnpinnedTabAreaRight
        '
        Me._MDIENT_PanelUnpinnedTabAreaRight.Dock = System.Windows.Forms.DockStyle.Right
        Me._MDIENT_PanelUnpinnedTabAreaRight.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))
        Me._MDIENT_PanelUnpinnedTabAreaRight.Location = New System.Drawing.Point(624, 0)
        Me._MDIENT_PanelUnpinnedTabAreaRight.Name = "_MDIENT_PanelUnpinnedTabAreaRight"
        Me._MDIENT_PanelUnpinnedTabAreaRight.Owner = Me.UltraDockManager1
        Me._MDIENT_PanelUnpinnedTabAreaRight.Size = New System.Drawing.Size(0, 442)
        Me._MDIENT_PanelUnpinnedTabAreaRight.TabIndex = 6
        '
        '_MDIENT_PanelUnpinnedTabAreaTop
        '
        Me._MDIENT_PanelUnpinnedTabAreaTop.Dock = System.Windows.Forms.DockStyle.Top
        Me._MDIENT_PanelUnpinnedTabAreaTop.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))
        Me._MDIENT_PanelUnpinnedTabAreaTop.Location = New System.Drawing.Point(21, 0)
        Me._MDIENT_PanelUnpinnedTabAreaTop.Name = "_MDIENT_PanelUnpinnedTabAreaTop"
        Me._MDIENT_PanelUnpinnedTabAreaTop.Owner = Me.UltraDockManager1
        Me._MDIENT_PanelUnpinnedTabAreaTop.Size = New System.Drawing.Size(603, 0)
        Me._MDIENT_PanelUnpinnedTabAreaTop.TabIndex = 7
        '
        '_MDIENT_PanelUnpinnedTabAreaBottom
        '
        Me._MDIENT_PanelUnpinnedTabAreaBottom.Dock = System.Windows.Forms.DockStyle.Bottom
        Me._MDIENT_PanelUnpinnedTabAreaBottom.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))
        Me._MDIENT_PanelUnpinnedTabAreaBottom.Location = New System.Drawing.Point(21, 442)
        Me._MDIENT_PanelUnpinnedTabAreaBottom.Name = "_MDIENT_PanelUnpinnedTabAreaBottom"
        Me._MDIENT_PanelUnpinnedTabAreaBottom.Owner = Me.UltraDockManager1
        Me._MDIENT_PanelUnpinnedTabAreaBottom.Size = New System.Drawing.Size(603, 0)
        Me._MDIENT_PanelUnpinnedTabAreaBottom.TabIndex = 8
        '
        '_MDIENT_PanelAutoHideControl
        '
        Me._MDIENT_PanelAutoHideControl.Controls.Add(Me.DockableWindow1)
        Me._MDIENT_PanelAutoHideControl.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))
        Me._MDIENT_PanelAutoHideControl.Location = New System.Drawing.Point(29, 0)
        Me._MDIENT_PanelAutoHideControl.Name = "_MDIENT_PanelAutoHideControl"
        Me._MDIENT_PanelAutoHideControl.Owner = Me.UltraDockManager1
        Me._MDIENT_PanelAutoHideControl.Size = New System.Drawing.Size(20, 568)
        Me._MDIENT_PanelAutoHideControl.TabIndex = 9
        '
        'DockableWindow1
        '
        Me.DockableWindow1.Controls.Add(Me.uebMenu)
        Me.DockableWindow1.Location = New System.Drawing.Point(0, 0)
        Me.DockableWindow1.Name = "DockableWindow1"
        Me.DockableWindow1.Owner = Me.UltraDockManager1
        Me.DockableWindow1.Size = New System.Drawing.Size(335, 568)
        Me.DockableWindow1.TabIndex = 17
        '
        'WindowDockingArea1
        '
        Me.WindowDockingArea1.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))
        Me.WindowDockingArea1.Location = New System.Drawing.Point(29, 0)
        Me.WindowDockingArea1.Name = "WindowDockingArea1"
        Me.WindowDockingArea1.Owner = Me.UltraDockManager1
        Me.WindowDockingArea1.Size = New System.Drawing.Size(244, 294)
        Me.WindowDockingArea1.TabIndex = 11
        Me.WindowDockingArea1.Visible = False
        '
        'MDI_Panel
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(7, 18)
        Me.ClientSize = New System.Drawing.Size(624, 442)
        Me.Controls.Add(Me._MDIENT_PanelAutoHideControl)
        Me.Controls.Add(Me.WindowDockingArea1)
        Me.Controls.Add(Me._MDIENT_PanelUnpinnedTabAreaTop)
        Me.Controls.Add(Me._MDIENT_PanelUnpinnedTabAreaBottom)
        Me.Controls.Add(Me._MDIENT_PanelUnpinnedTabAreaLeft)
        Me.Controls.Add(Me._MDIENT_PanelUnpinnedTabAreaRight)
        Me.Controls.Add(Me._MDIENT_Panel_Toolbars_Dock_Area_Left)
        Me.Controls.Add(Me._MDIENT_Panel_Toolbars_Dock_Area_Right)
        Me.Controls.Add(Me._MDIENT_Panel_Toolbars_Dock_Area_Bottom)
        Me.Controls.Add(Me._MDIENT_Panel_Toolbars_Dock_Area_Top)
        Me.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))
        Me.IsMdiContainer = True
        Me.Name = "MDI_Panel"
        Me.Text = "Test"
        Me.WindowState = System.Windows.Forms.FormWindowState.Maximized
        CType(Me.uebMenu, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.UltraToolbarsManager1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.UltraDockManager1, System.ComponentModel.ISupportInitialize).EndInit()
        Me._MDIENT_PanelAutoHideControl.ResumeLayout(False)
        Me.DockableWindow1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub MDIENT_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Cursor.Current = Cursors.WaitCursor

        ''---掛載Online Help----
        Dim clsHelp As New clsOnlineHelp
        clsHelp.AddEventToForm(Me)

        'set BackColor
        Call setMDIBackColor(Me)

        ModuleNo = "SYS"

        ' 2016/05/09 YF, 產生選單
        GenerateMenu()

        '3.Get EnterpriseNo-----------------------------------------------------------------------------------------------------------
        Call funGetEnterpriseNo()

        '4.版本檢查
        Call ChkVersion()

        'Me.Text = Me.Text & " - " & GetClientVersion()    'Gary Lu 20120718:標題加上版本編號

        '5.Execute Change Resource-----------------------------------------------------------------------------------------------------
        'Call ExeChangeResource(Me, gLanguageMode)

        '6.Set iMESExceptionManager LanguageMode---------------------------------------------------------------------------------------
        iMESExceptionManager.ExceptionManager.LanguageMode = gLanguageMode

        Cursor.Current = Cursors.Default

    End Sub

#Region " UltraWinToolbars Menu & ToolBar  Function  "

    Private Function funCreateUltraPopupMenuToolbar(ByRef ParentMenuItem As iMESMenuItem) As PopupMenuTool


        'PopupMenuTool
        popMDI = New PopupMenuTool(ParentMenuItem.Name)
        popMDI.SharedProps.Tag = ParentMenuItem.Name
        popMDI.SharedProps.ToolTipText = ParentMenuItem.Name
        UltraToolbarsManager1.Tools.Add(popMDI)

        Return popMDI

    End Function

    Private Function funCreateUltraButtonMenuToolbar(ByRef ParentMenuItem As iMESMenuItem)

        'Button Tool
        btlMDI = New ButtonTool(ParentMenuItem.Name)
        btlMDI.SharedProps.Tag = ParentMenuItem.Name
        btlMDI.SharedProps.ToolTipText = ParentMenuItem.Name
        UltraToolbarsManager1.Tools.Add(btlMDI)

        utbMDIMenu.Tools.AddRange(New Infragistics.Win.UltraWinToolbars.ToolBase() {btlMDI})

    End Function

    Private Sub funCreateUltraMenuItemToolbar(ByRef tmppopMDI As PopupMenuTool, ByRef ParentMenuItem As iMESMenuItem, Optional ByVal btlEnabled As Boolean = True)

        If ParentMenuItem.Name.ToUpper = "EN" Or ParentMenuItem.Name.ToUpper = "ZH-CHT" Or
            ParentMenuItem.Name.ToUpper = "ZH-CHS" Or ParentMenuItem.Name.ToUpper = "JP" Or
            ParentMenuItem.Name.ToUpper = "KOR" Or ParentMenuItem.Name.ToUpper = "THAI" Or
            ParentMenuItem.Name.ToUpper = "VIET" Then

            funCreateUltraStatButtonToolbar(tmppopMDI, ParentMenuItem, , "LanguageMode")

        ElseIf ParentMenuItem.Checkable = True Then

            funCreateUltraStatButtonToolbar(tmppopMDI, ParentMenuItem, btlEnabled)

        Else

            '產生UltraToolBar Button
            btlMDI = New ButtonTool(ParentMenuItem.Name)
            btlMDI.SharedProps.Tag = ParentMenuItem.Name
            btlMDI.SharedProps.ToolTipText = ParentMenuItem.Name
            btlMDI.SharedProps.Enabled = btlEnabled

            If Not ParentMenuItem.Icon Is Nothing Then
                'Image
                imlMDI.Images.Add(ParentMenuItem.Icon)

                btlMDI.SharedProps.AppearancesSmall.Appearance.Image = imlMDI.Images.Count - 1

            End If


            btlMDI.SharedProps.Shortcut = ParentMenuItem.Shortcut

            UltraToolbarsManager1.Tools.Add(btlMDI)
            tmppopMDI.Tools.AddRange(New Infragistics.Win.UltraWinToolbars.ToolBase() {btlMDI})

        End If


    End Sub

    Private Sub funCreateUltraStatButtonToolbar(ByRef tmppopMDI As PopupMenuTool, ByRef ParentMenuItem As iMESMenuItem, Optional ByVal btlEnabled As Boolean = True, Optional ByVal tmpOptionSetKey As String = "")

        '產生UltraToolBar Button
        sbtMDI = New StateButtonTool(ParentMenuItem.Name)
        sbtMDI.MenuDisplayStyle = Infragistics.Win.UltraWinToolbars.StateButtonMenuDisplayStyle.DisplayCheckmark
        sbtMDI.SharedProps.Tag = ParentMenuItem.Name
        sbtMDI.SharedProps.ToolTipText = ParentMenuItem.Name
        sbtMDI.SharedProps.Enabled = btlEnabled
        sbtMDI.OptionSetKey = tmpOptionSetKey

        If gLanguageMode.ToUpper = ParentMenuItem.Name.ToUpper Or ParentMenuItem.Checked = True Then
            sbtMDI.Checked = True
        End If


        If Not ParentMenuItem.Icon Is Nothing Then
            'Image
            imlMDI.Images.Add(ParentMenuItem.Icon)

            sbtMDI.SharedProps.AppearancesSmall.Appearance.Image = imlMDI.Images.Count - 1

        End If

        sbtMDI.SharedProps.Shortcut = ParentMenuItem.Shortcut

        UltraToolbarsManager1.Tools.Add(sbtMDI)
        tmppopMDI.Tools.AddRange(New Infragistics.Win.UltraWinToolbars.ToolBase() {sbtMDI})

    End Sub

    Private Sub funCreateUltraToolbar(ByRef ParentMenuItem As iMESMenuItem)

        '產生UltraToolBar Button
        If Not ParentMenuItem.Icon Is Nothing Then
            'Image
            imlMDI.Images.Add(ParentMenuItem.Icon)
            'Button
            btlMDI = New ButtonTool(ParentMenuItem.Name)
            btlMDI.SharedProps.Tag = ParentMenuItem.Name
            btlMDI.SharedProps.ToolTipText = ParentMenuItem.Name
            btlMDI.SharedProps.AppearancesSmall.Appearance.Image = imlMDI.Images.Count - 1
            utbMDI.Tools.AddRange(New Infragistics.Win.UltraWinToolbars.ToolBase() {btlMDI})
        End If

    End Sub

#End Region


#Region " UltraWinExplorerBar & UltraWinToolbars Events  "


    Private Sub uebRPTMenu_ItemClick(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinExplorerBar.ItemEventArgs) Handles uebMenu.ItemClick
        ExecutingFunction(e.Item.Key)
    End Sub

    Private Sub uebRPTMenu_ItemDoubleClick(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinExplorerBar.ItemEventArgs) Handles uebMenu.ItemDoubleClick
        ExecutingFunction(e.Item.Key)
    End Sub

    Private Sub UltraToolbarsManager1_ToolClick(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinToolbars.ToolClickEventArgs) Handles UltraToolbarsManager1.ToolClick

        Dim strOptionSetKey As String = ""

        If (e.Tool.GetType Is GetType(StateButtonTool)) Then
            strOptionSetKey = CType(e.Tool, StateButtonTool).OptionSetKey
        End If

        ExecutingFunction(e.Tool.Key, strOptionSetKey)

    End Sub

    Protected Sub ExecutingFunction(ByVal FunctionKey As String, Optional OptionSetKey As String = "")
        Dim strFormName As String
        Dim TempChild As Form
        Dim CurrentForm As Form
        Cursor.Current = Cursors.WaitCursor
        Try

            ' 2016/05/09 YF, 重新產生選單
            If OptionSetKey = "MODULE" Then
                ModuleNo = FunctionKey.Replace("Module", "")
                GenerateMenu()
                Exit Sub
            End If

            Select Case FunctionKey.ToUpper
                Case "EXIT"
                    'End
                    Me.Close()
                Case "CASCADE"
                    Me.LayoutMdi(MdiLayout.Cascade)
                Case "VERTICAL"
                    Me.LayoutMdi(MdiLayout.TileVertical)
                Case "HORIZONTAL"
                    Me.LayoutMdi(MdiLayout.TileHorizontal)

                'Change Language Mode
                Case "zh-CHT".ToUpper
                    gLanguageMode = "zh-CHT"

                    iMESExceptionManager.ExceptionManager.LanguageMode = gLanguageMode

                    CurrentForm = Form.ActiveForm

                    If Not CurrentForm Is Nothing Then
                        Call ExeChangeResource(CurrentForm, gLanguageMode)
                    End If

                    '變更畫面上的表單（僅限MDI Child Form）

                    For Each TempChild In Me.MdiChildren
                        If Not (TempChild Is CurrentForm) Then
                            Call ExeChangeResource(TempChild, gLanguageMode)
                        End If
                    Next

                '變更其他語系的Checked為False
                'Call funChangeChecked(mnuMenuItem)

                Case "zh-CHS".ToUpper
                    gLanguageMode = "zh-CHS"

                    iMESExceptionManager.ExceptionManager.LanguageMode = gLanguageMode

                    CurrentForm = Form.ActiveForm

                    If Not CurrentForm Is Nothing Then
                        Call ExeChangeResource(CurrentForm, gLanguageMode)
                    End If

                    '變更畫面上的表單（僅限MDI Child Form）

                    For Each TempChild In Me.MdiChildren
                        If Not (TempChild Is CurrentForm) Then
                            Call ExeChangeResource(TempChild, gLanguageMode)
                        End If
                    Next

                '變更其他語系的Checked為False
                'Call funChangeChecked(mnuMenuItem)

                Case "en".ToUpper
                    gLanguageMode = "en"

                    iMESExceptionManager.ExceptionManager.LanguageMode = gLanguageMode

                    CurrentForm = Form.ActiveForm

                    If Not CurrentForm Is Nothing Then
                        Call ExeChangeResource(CurrentForm, gLanguageMode)
                    End If

                    '變更畫面上的表單（僅限MDI Child Form）
                    For Each TempChild In Me.MdiChildren
                        If Not (TempChild Is CurrentForm) Then
                            Call ExeChangeResource(TempChild, gLanguageMode)
                        End If
                    Next

                '變更其他語系的Checked為False
                'Call funChangeChecked(mnuMenuItem)

                Case "jp".ToUpper
                    gLanguageMode = "jp"

                    iMESExceptionManager.ExceptionManager.LanguageMode = gLanguageMode

                    CurrentForm = Form.ActiveForm

                    If Not CurrentForm Is Nothing Then
                        Call ExeChangeResource(CurrentForm, gLanguageMode)
                    End If

                    '變更畫面上的表單（僅限MDI Child Form）
                    For Each TempChild In Me.MdiChildren
                        If Not (TempChild Is CurrentForm) Then
                            Call ExeChangeResource(TempChild, gLanguageMode)
                        End If
                    Next

                '變更其他語系的Checked為False
                'Call funChangeChecked(mnuMenuItem)

                Case "kor".ToUpper  'Korea(韓國語系)
                    gLanguageMode = "kor"

                    iMESExceptionManager.ExceptionManager.LanguageMode = gLanguageMode

                    CurrentForm = Form.ActiveForm

                    If Not CurrentForm Is Nothing Then
                        Call ExeChangeResource(CurrentForm, gLanguageMode)
                    End If

                    '變更畫面上的表單（僅限MDI Child Form）
                    For Each TempChild In Me.MdiChildren
                        If Not (TempChild Is CurrentForm) Then
                            Call ExeChangeResource(TempChild, gLanguageMode)
                        End If
                    Next

                '變更其他語系的Checked為False
                'Call funChangeChecked(mnuMenuItem)

                Case "thai".ToUpper 'Thailand(泰國語系)
                    gLanguageMode = "thai"

                    iMESExceptionManager.ExceptionManager.LanguageMode = gLanguageMode

                    CurrentForm = Form.ActiveForm

                    If Not CurrentForm Is Nothing Then
                        Call ExeChangeResource(CurrentForm, gLanguageMode)
                    End If

                    '變更畫面上的表單（僅限MDI Child Form）
                    For Each TempChild In Me.MdiChildren
                        If Not (TempChild Is CurrentForm) Then
                            Call ExeChangeResource(TempChild, gLanguageMode)
                        End If
                    Next

                '變更其他語系的Checked為False
                'Call funChangeChecked(mnuMenuItem)

                Case "viet".ToUpper 'VietNam(越南語系)
                    gLanguageMode = "viet"

                    iMESExceptionManager.ExceptionManager.LanguageMode = gLanguageMode

                    CurrentForm = Form.ActiveForm

                    If Not CurrentForm Is Nothing Then
                        Call ExeChangeResource(CurrentForm, gLanguageMode)
                    End If

                    '變更畫面上的表單（僅限MDI Child Form）
                    For Each TempChild In Me.MdiChildren
                        If Not (TempChild Is CurrentForm) Then
                            Call ExeChangeResource(TempChild, gLanguageMode)
                        End If
                    Next

                '變更其他語系的Checked為False
                'Call funChangeChecked(mnuMenuItem)

                Case "ABOUTME"
                    strFormName = "frmAboutMe"
                    blnShow = False
                    For i = 0 To Me.MdiChildren.Length - 1
                        If Me.MdiChildren(i).Name = strFormName Then
                            Me.MdiChildren(i).Focus()
                            blnShow = True
                            Exit For
                        End If
                    Next

                    If blnShow = False Then '目前沒有顯示

                        Dim mainAssembly As System.Reflection.Assembly = LoadAssembly("COM_AboutMe.dll")

                        If (mainAssembly Is Nothing) Then
                            Exit Sub
                        End If

                        Dim objForm As Form = mainAssembly.CreateInstance(mainAssembly.GetName.Name & "." & strFormName)

                        If objForm Is Nothing Then  'Form不存在
                            MsgBox("Form : " & strFormName & " is not exist!!", MsgBoxStyle.Exclamation)
                            Exit Sub
                        End If

                        objForm.MdiParent = MDI_Panel.ActiveForm
                        objForm.AutoScaleMode = Windows.Forms.AutoScaleMode.None
                        objForm.Show()

                    End If

                Case Else

                    Dim strExecutionFile As String = dsData.Tables(strUserPriv).Select("FunctionNo='" & FunctionKey & "'")(0)("ExecutionFile")
                    strFormName = dsData.Tables(strUserPriv).Select("FunctionNo='" & FunctionKey & "'")(0)("FormName")

                    If (Not Application.OpenForms.Item(strFormName) Is Nothing) AndAlso (strFormName <> "frmRPT_Script") Then
                        If Application.OpenForms.Item(strFormName).WindowState <> FormWindowState.Normal Then Application.OpenForms.Item(strFormName).WindowState = FormWindowState.Normal
                        Application.OpenForms.Item(strFormName).Focus()
                        Exit Sub
                    End If

                    Dim mainAssembly As System.Reflection.Assembly = LoadAssembly(strExecutionFile)

                    If (mainAssembly Is Nothing) Then
                        Exit Sub
                    End If

                    'Show Form
                    'Dim mainAssembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly
                    'Dim objForm As Form = mainAssembly.CreateInstance(mainAssembly.EntryPoint.ReflectedType.Namespace & "." & strFormName)
                    Dim objForm As Form = mainAssembly.CreateInstance(mainAssembly.GetName.Name & "." & strFormName)

                    If objForm Is Nothing Then  'Form不存在
                        MsgBox("Form : " & strFormName & " is not exist!!", MsgBoxStyle.Exclamation)
                        Exit Sub
                    End If

                    objForm.MdiParent = MDI_Panel.ActiveForm

                    '設定值予公用變數
                    Dim myfieldinfo() As System.Reflection.FieldInfo
                    Dim myType As Type = objForm.GetType
                    Dim i As Integer
                    myfieldinfo = myType.GetFields()
                    For i = 0 To myfieldinfo.Length - 1
                        If myfieldinfo(i).Name.ToUpper = "PrivFunNo".ToUpper Then
                            myfieldinfo(i).SetValue(objForm, FunctionKey)
                        End If
                    Next i
                    objForm.AutoScaleMode = Windows.Forms.AutoScaleMode.None
                    objForm.Show()

            End Select

        Catch ex As Exception
            MsgBox("This Function can not be executed. " & ex.Message, MsgBoxStyle.Exclamation, "Warning")
            'ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
        End Try
        Cursor.Current = Cursors.Default
    End Sub

#End Region

    Private Sub funLoadUserPriv()

        If (Not dsData.Tables(strUserPriv) Is Nothing) Then
            dsData.Tables.Remove(strUserPriv)
        End If

        Dim XmlDoc As New XmlDocument                       '處理Xml字串之物件?
        Dim tmpStringReader As System.IO.StringReader           '將字串轉換成可讀入DataSet的物件
        Dim InXml, OutXml, strIdentity, strParameter As String  '呼叫WS的字串參數
        Dim XmlData, XmlSchema As String                        '儲存取回之資料及資料結構

        '組InXml的字串
        strIdentity = CombineXMLIdentity(gComputerName, gUserNo, GetNow())
        strParameter = CombineXMLParameter("userno", "UserNo", "String", gUserNo, "")
        strParameter = strParameter & CombineXMLParameter("moduleno", "ModuleNo", "String", ModuleNo, "")
        InXml = CombineXMLRequest(strIdentity, strParameter)

        Try
            OutXml = InvokeSrv("wsUSR.LoadUserPriv", InXml)
            XmlDoc.LoadXml(OutXml)

            If ChkExecutionSuccess(XmlDoc) Then
                strUserPriv = XmlDoc.GetElementsByTagName("returnvalue").Item(0).SelectNodes("loaduserpriv").Item(0).SelectNodes("name").Item(0).InnerXml
                '取出Data
                XmlData = XmlDoc.DocumentElement.GetElementsByTagName("loaduserpriv").Item(0).SelectNodes("value").Item(0).InnerXml
                If XmlData <> "" Then
                    tmpStringReader = New System.IO.StringReader(XmlData)
                    dsData.ReadXml(tmpStringReader, XmlReadMode.InferSchema)
                    tmpStringReader.Close()
                End If
            Else
                MsgBox(GetExceptionSysMsg(XmlDoc) & Chr(13) & GetExceptionMesMsg(XmlDoc), MsgBoxStyle.Exclamation)
                Exit Sub
            End If

        Catch e1 As Exception
            MsgBox("Unexpected Error. Load User's Priv Failed," & e1.Message, MsgBoxStyle.Exclamation)
        Finally
            XmlDoc = Nothing
            tmpStringReader = Nothing

        End Try

    End Sub

    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub

    Public Sub funGetEnterpriseNo()

        Dim XmlDoc As New XmlDocument
        Dim tmpStringReader As System.IO.StringReader
        Dim InXml, OutXml, strIdentity, strParameter, XmlData, XmlSchema, strPara As String
        Dim dsTemp As New DataSet

        strIdentity = CombineXMLIdentity(gComputerName, gUserNo, GetNow())
        strParameter = CombineXMLParameter("parameterno", "ParameterNo", "String", "EnterpriseNo", "")
        InXml = CombineXMLRequest(strIdentity, strParameter)

        Try

            OutXml = InvokeSrv("wsSYS.LoadParameter", InXml)

            XmlDoc.LoadXml(OutXml)

            If ChkExecutionSuccess(XmlDoc) Then

                strPara = XmlDoc.GetElementsByTagName("returnvalue").Item(0).SelectNodes("loadparameter").Item(0).SelectNodes("name").Item(0).InnerXml

                XmlSchema = XmlDoc.DocumentElement.GetElementsByTagName("loadparameter").Item(0).SelectNodes("schema").Item(0).InnerXml

                If XmlSchema <> "" Then
                    '將XML讀入String Reader object中,因為Dataset讀入XML時必須透過String Reader物件
                    tmpStringReader = New System.IO.StringReader(XmlSchema)
                    dsTemp.ReadXmlSchema(tmpStringReader)
                    tmpStringReader.Close()
                End If

                XmlData = XmlDoc.DocumentElement.GetElementsByTagName("loadparameter").Item(0).SelectNodes("value").Item(0).InnerXml

                If XmlData <> "" Then
                    tmpStringReader = New System.IO.StringReader(XmlData)
                    dsTemp.ReadXml(tmpStringReader, XmlReadMode.InferSchema)
                    tmpStringReader.Close()
                End If

                If dsTemp.Tables(strPara).Rows.Count > 0 Then
                    gEnterpriseNo = dsTemp.Tables(strPara).Rows(0)("ParameterValue").ToString.ToUpper
                End If

            Else
                MsgBox(GetExceptionSysMsg(XmlDoc) & Chr(13) & GetExceptionMesMsg(XmlDoc), MsgBoxStyle.Exclamation)
            End If

        Catch ex As Exception
            MsgBox("Unexpected Error. GetEnterpriseNo failed, " & ex.Message, MsgBoxStyle.Exclamation)
        Finally
            XmlDoc = Nothing
            tmpStringReader = Nothing
            dsTemp = Nothing
        End Try

    End Sub

    ' 2016/05/09 YF, 產生模組選單
    Private Sub GenerateModuleItems()

        Dim aryModule() As String = {"ACC", "AUT", "DT", "EMS", "ENT", "EQP", "IEW", "INV", "ISU", "MSA", "MTL", "OE", "OP", "PM", "PRD", "PRS", "QC", "RPT", "SMD", "SPC", "SYS", "USR", "WIP"}
        Dim popModule As PopupMenuTool
        Dim sbt As StateButtonTool

        Try

            popModule = New PopupMenuTool("MODULE")
            popModule.SharedProps.Tag = "MODULE"
            popModule.SharedProps.ToolTipText = "MODULE"
            UltraToolbarsManager1.Tools.Add(popModule)

            '產生UltraToolBar Button
            For Each m As String In aryModule

                sbt = New StateButtonTool(m & "Module")
                sbt.MenuDisplayStyle = Infragistics.Win.UltraWinToolbars.StateButtonMenuDisplayStyle.DisplayCheckmark
                sbt.CustomizedCaption = m
                sbt.SharedProps.Tag = m
                sbt.SharedProps.ToolTipText = m
                sbt.SharedProps.Enabled = True
                sbt.OptionSetKey = "MODULE"

                If ModuleNo = m Then
                    sbt.Checked = True
                End If

                UltraToolbarsManager1.Tools.Add(sbt)
                popModule.Tools.AddRange(New Infragistics.Win.UltraWinToolbars.ToolBase() {sbt})

            Next

            Me.utbMDIMenu.Tools.AddRange(New Infragistics.Win.UltraWinToolbars.ToolBase() {popModule})

            Me.utbMDIMenu.Tools.Item("MODULE").CustomizedIsFirstInGroup = DefaultableBoolean.True

        Catch ex As Exception
            MsgBox("GenerateModuleMenu failed, " & ex.Message, MsgBoxStyle.Exclamation)
        End Try

    End Sub

    Private Sub GenerateMenu()

        Try

            ' 2016/05/09 YF, 清空選單
            RemoveObject()

            '取出User Privileges
            Call funLoadUserPriv()

            '1.Create MainMenu-------------------------------------------------------------------------------------------------------------
            Dim strFileName As String
            strFileName = GetMainMenuFileName()

            '檢查檔案是否存在
            If Dir(strFileName) = "" Then  'File not exist
                MsgBox(strFileName & vbCrLf & "is not exist,Load MDI Form failed!!", MsgBoxStyle.Exclamation)
                Exit Sub
            End If

            '將處理 MenuItem 被點選的函數以 EventHandler Delegation 傳給 mnuMainMenu
            Dim mnuMainMenu As New iMESMainMenu.iMESMainMenuControl(strFileName, Nothing)

            'Add ExplorerBar MainMenu By carl 2007.08.14
            Dim j As Integer
            Dim tempMenuSplit As Integer = defInteger
            Dim panelmenu As MainMenu = New MainMenu(mnuMainMenu.CreateMainMenu(ModuleNo))
            Dim tmpMenuItem1 As iMESMenuItem
            Dim tmpPopMenu As PopupMenuTool
            UltraDockManager1.ControlPanes(0).Pinned = False
            UltraDockManager1.ShowCloseButton = False

            uebMenu.GroupSettings.AllowDrag = DefaultableBoolean.False
            uebMenu.GroupSettings.AllowEdit = DefaultableBoolean.False
            uebMenu.GroupSettings.AllowItemDrop = DefaultableBoolean.False
            uebMenu.ItemSettings.AllowDragCopy = UltraWinExplorerBar.ItemDragStyle.None
            uebMenu.ItemSettings.AllowDragMove = UltraWinExplorerBar.ItemDragStyle.None
            uebMenu.ItemSettings.AllowEdit = DefaultableBoolean.False
            uebMenu.ShowDefaultContextMenu = False

            uebMenu.ItemSettings.UseDefaultImage = Infragistics.Win.DefaultableBoolean.False
            uebMenu.ItemSettings.MaxLines = 2
            Dim h As Integer = -1 '//^_^ADD BY H-03274  20190806 FOR 
            If Not dsData.Tables(strUserPriv) Is Nothing Then   '沒有任何權限,所有Privilege MenuItem都不可使用

                For i = 0 To panelmenu.MenuItems.Count - 1
                    tmpMenuItem1 = CType(panelmenu.MenuItems(i), iMESMenuItem)

                    'If i <= panelmenu.MenuItems.Count - 4 Then
                    '   uebMenu.Groups.Add(tmpMenuItem1.Text.ToUpper)
                    '   uebMenu.Groups(i).Expanded = True 
                    'End If '//^_^MARK BY H-03274  20190806 FOR 对Mainmenu处理的漏洞。会超出索引界限

                    '//^_^ ADD BY H-03274  20190806 =============begin============== 
                    '//功能描述：对Mainmenu处理的漏洞。会超出索引界限
                    If tmpMenuItem1.Text.ToUpper <> "LANGUAGE" And tmpMenuItem1.Text.ToUpper <> "WINDOWS" And tmpMenuItem1.Text.ToUpper <> "EXIT" Then
                        h += 1
                        uebMenu.Groups.Add(tmpMenuItem1.Text.ToUpper)
                        uebMenu.Groups(h).Expanded = True
                    End If
                    '//^_^ ADD BY H-03274  20190806 ==============END=============== 

                    If tmpMenuItem1.Name.ToUpper = "EXIT" Then

                        funCreateUltraButtonMenuToolbar(tmpMenuItem1)

                    Else

                        tmpPopMenu = funCreateUltraPopupMenuToolbar(tmpMenuItem1)

                        For j = 0 To tmpMenuItem1.MenuItems.Count - 1
                            If CType(tmpMenuItem1.MenuItems(j), iMESMenuItem).MenuType = iMESMenuItem.mesMenuType.MenuPrivilege Then
                                If dsData.Tables(strUserPriv).Select("FunctionNo='" & tmpMenuItem1.MenuItems(j).Text.ToUpper & "'").Length > 0 Then
                                    funCreateUltraMenuItemToolbar(tmpPopMenu, CType(tmpMenuItem1.MenuItems(j), iMESMenuItem))


                                    uebMenu.Groups(h).Items.Add(tmpMenuItem1.MenuItems(j).Text)  '//^_^MODI BY H-03274  20190806 FOR i-->h


                                    funCreateUltraToolbar(CType(tmpMenuItem1.MenuItems(j), iMESMenuItem))

                                        If tempMenuSplit = j Then
                                            tmpPopMenu.Tools(tmpMenuItem1.MenuItems(j).Text).InstanceProps.IsFirstInGroup = True
                                        End If

                                    Else
                                        funCreateUltraMenuItemToolbar(tmpPopMenu, CType(tmpMenuItem1.MenuItems(j), iMESMenuItem), False)

                                    If tempMenuSplit = j Then
                                        tmpPopMenu.Tools(tmpMenuItem1.MenuItems(j).Text).InstanceProps.IsFirstInGroup = True
                                    End If

                                End If

                            ElseIf CType(tmpMenuItem1.MenuItems(j), iMESMenuItem).MenuType = iMESMenuItem.mesMenuType.MenuString Then


                                funCreateUltraMenuItemToolbar(tmpPopMenu, CType(tmpMenuItem1.MenuItems(j), iMESMenuItem))

                                If tempMenuSplit = j Then
                                    tmpPopMenu.Tools(tmpMenuItem1.MenuItems(j).Text).InstanceProps.IsFirstInGroup = True
                                End If

                            ElseIf CType(tmpMenuItem1.MenuItems(j), iMESMenuItem).MenuType = iMESMenuItem.mesMenuType.MenuSplit Then

                                tempMenuSplit = j + 1

                            End If

                        Next

                        utbMDIMenu.Tools.AddRange(New Infragistics.Win.UltraWinToolbars.ToolBase() {tmpPopMenu})

                    End If

                Next

            End If

            'Add UltraToolBar-----------------------------------------------------------------------------------------------------------------
            If utbMDI.Tools.Count > 0 Then
                imlMDI.ImageSize = New Size(24, 24)
                utbMDI.Text = "Toolbar"
                utbMDI.Settings.ToolDisplayStyle = ToolDisplayStyle.ImageAndText
                utbMDI.Settings.CaptionPlacement = TextPlacement.Default
                utbMDI.IsMainMenuBar = False
                utbMDI.DockedPosition = DockedPosition.Top
                UltraToolbarsManager1.Style = ToolbarStyle.Office2003
                UltraToolbarsManager1.ImageListSmall = imlMDI
                UltraToolbarsManager1.Toolbars.Add(utbMDI)
            End If

            'Add Menu UltraToolBar-----------------------------------------------------------------------------------------------------------------
            If utbMDIMenu.Tools.Count > 0 Then
                imlMDI.ImageSize = New Size(24, 24)
                utbMDIMenu.Text = "MainMenu"
                utbMDIMenu.Settings.ToolDisplayStyle = ToolDisplayStyle.ImageAndText
                utbMDIMenu.Settings.CaptionPlacement = TextPlacement.Default
                utbMDIMenu.IsMainMenuBar = True
                utbMDIMenu.DockedPosition = DockedPosition.Top
                UltraToolbarsManager1.OptionSets.Add(OptionSet1)
                UltraToolbarsManager1.Style = ToolbarStyle.Office2003
                UltraToolbarsManager1.ImageListSmall = imlMDI
                UltraToolbarsManager1.Toolbars.Add(utbMDIMenu)
                UltraToolbarsManager1.Toolbars("MainMenu").ToolbarsManager.ToolbarSettings.ToolSpacing = 5
            End If

            ' 2016/05/09 YF, 產生模組選單 
            GenerateModuleItems()

        Catch ex As Exception
            MsgBox("GenerateMenuItem failed, " & ex.Message, MsgBoxStyle.Exclamation)
        Finally
            Me.Text = "Test"
            ExeChangeResource(Me, gLanguageMode)
        End Try

    End Sub

    Private Sub RemoveObject()

        uebMenu.Groups.Clear()
        utbMDIMenu.Tools.Clear()
        utbMDI.Tools.Clear()
        UltraToolbarsManager1.Toolbars.Clear()
        UltraToolbarsManager1.Tools.Clear()
        UltraToolbarsManager1.OptionSets.Clear()
        Me.UltraDockManager1.DockAreas(0).Panes.Item(0).Text = ModuleNo
        Me.UltraDockManager1.DockAreas(0).Panes.Item(0).Key = ModuleNo & "Module"

        For i As Integer = Application.OpenForms.Count - 1 To 0 Step -1

            If (Application.OpenForms.Item(i).Name <> "MDI_Panel") Then
                Application.OpenForms.Item(i).Close()
            End If

        Next

    End Sub

End Class
